#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;

void solve(){
        LL n;
        cin >> n;

        if(n == 1){
            cout << 3 << '\n';
            return;
        }

        int res;
        for(int i = 0; i < 31; i ++){

            if((n >> i) & 1){
                int k = (1 << i);
                if(k != n){
                    res = k;
                    cout << res << '\n';
                    return;  
                }else{
                    res = k + 1;
                    cout << res << '\n';
                }
            }

            
        }

        
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    while(T--){
        solve();
    }


    return 0;
}